﻿using System;
using System.Windows;
using System.Windows.Controls;

using SBPweb.Forge.Contracts.Extensibility;

using SBPweb.Communication.Shared.Library.Conversations;

using SBPweb.Communication.Client.Library.Xmpp.Conversations;
using SBPweb.Communication.Client.Controls.Xmpp.Conversations;

using SBPweb.PROvibe.Presentation.Client.Controls.Containers;

namespace SBPweb.PROvibe.Modules.Client.Communication.Xmpp.Controls
{

    public partial class ConversationWindow : UserControlWindow
    {

        #region Private fields

        private ConversationBase xmppConv;

        #endregion

        #region Constructor logic

        public ConversationWindow()
        {
            InitializeComponent();
        }

        public ConversationWindow(ConversationBase conversation)
            : this()
        {
            this.Conversation = conversation;
            this.Conversation.MessageReceived += new EventHandler<MessageBaseEventArgs>(Conversation_MessageReceived);
            this.ParentLayoutRoot = (Application.Current as IExtendable).Get<Panel>("RootPanel");
            this.Closed += new EventHandler(ConversationWindow_Closed);
        }

        #endregion

        #region Property accessors

        public ConversationBase Conversation
        {
            get
            {
                if (xmppConversation == null)
                {
                    return xmppConv;
                }
                return xmppConversation.Conversation;
            }
            protected set
            {
                if (xmppConversation != null)
                {
                    xmppConversation.Conversation = value;
                }
                xmppConv = value;
                Title = value.Title;
            }
        }

        #endregion

        #region Methods

        private void ConversationWindow_Closed(object sender, EventArgs e)
        {
        }

        private void Conversation_MessageReceived(object sender, MessageBaseEventArgs e)
        {
            //this.Show();
        }

        #endregion

    }
    
}